<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('编辑')"/>
    <th:block th:include="include :: select2-css"/>
    <th:block th:include="include :: datetimepicker-css" />
</head>
<body>
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="form-user-add" class="form-horizontal">
                <a style="margin-left: 20px;margin-top: 8px" class="btn btn-primary btn-rounded btn-sm" onclick="downloadTrainingProgramTeacher()">下载训练计划</a>
                <a style="margin-left: 20px;margin-top: 8px" class="btn btn-primary btn-rounded btn-sm" onclick="downloadDataRecordTeacher()">下载项目记录表</a>
                <div class="select-list" style="margin-top: 10px">
                    <input id="childId" name="childId" type="hidden" th:value="*{childId}"/>
                    <input id="projectType" name="projectType" type="hidden" th:value="*{projectType}"/>
                    <input id="scheduleTime" name="scheduleTime" type="hidden" th:value="*{scheduleTime}"/>
                    <input id="teacherName" name="teacherName" type="hidden" th:value="*{teacherName}"/>
                    <input id="isNewProgram" name="isNewProgram" type="hidden" th:value="*{isNewProgram}"/>
                    <ul>
                        <li>
                            <label style="width: 80px">学生姓名：</label>
                            <input type="text" name="childName" readonly="true" th:value="*{childName}"/>
                        </li>
                        <li>
                            <label style="width: 80px">年龄：</label>
                            <input type="text" name="childAge" readonly="true" th:value="*{childAge}"/>
                        </li>
                        <li>
                            <label style="width: 80px">月份：</label>
                            <input type="text" name="monthTime" readonly="true" th:value="*{monthTime}"/>
                        </li>
                        <li>
                            <label style="width: 80px">课程名称：</label>
                            <input type="text" name="projectName" readonly="true" th:value="*{projectName}"/>
                        </li>
                    </ul>
                </div>
            </form>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
        <div class="col-sm-offset-5 col-sm-10">
            <button type="button" class="btn btn-sm btn-danger" onclick="closeItem()"><i class="fa fa-reply-all"></i>关 闭</button>
        </div>
    </div>
</div>


<th:block th:include="include :: footer"/>
<th:block th:include="include :: select2-js"/>
<th:block th:include="include :: datetimepicker-js" />
<script th:inline="javascript">
    // 字典
    var trainingModuleType = [[${@dict.getType('business_training_module')}]];
    var prefix = ctx + "education/childtrainingProgram";
    var editPrefix = ctx + "education/schedule";
    $(function () {
        var options = {
            url: prefix + '/findByChildAndProjecttypeTable',
            pagination: false,
            showSearch: false,
            showRefresh: false,
            showToggle: false,
            showColumns: false,
            queryParams: queryParams,
            columns: [
                {
                    field: 'id',
                    title: '',
                    visible: false

                },
                {
                    field: 'trainingNum',
                    align: "center",
                    visible: false
                },
                {
                    title: '题号',
                    align: "center",
                    formatter: function (value, row, index) {
                       return index+1;
                    }
                },
                {
                    field: 'trainingModule',
                    title: '训练目标',
                    align: "center",
                    formatter: function (value, row, index) {
                        if ($.common.isNotEmpty(value)) {
                            return $.table.selectDictLabel(trainingModuleType, value);
                        } else {
                            return null;
                        }
                    }
                },
                {
                    field: 'trainingName',
                    title: '训练项目名称',
                    align: "center"
                },
                {
                    field: 'trainingContent',
                    title: '训练项目描述',
                    align: "center"
                }
                ]
        };
        $.table.init(options);
    });




    function queryParams(params) {
        var childId = $("#childId").val();
        var projectType = $("#projectType").val();
        var scheduleTime = $("#scheduleTime").val();
        var search = $.table.queryParams(params);
        search.childId = childId;
        search.pageSize = 10000;
        search.projectType = projectType;
        search.trainingProgramNumber = scheduleTime;
        search.isChoosed = 1;
        search.requestType = 3;
        return search;
    }

    function downloadTrainingProgramTeacher() {
        var centerId = "";
        var selectIndex = window.parent.document.getElementById('parentSchoolList').selectedIndex;
        if (selectIndex >= 0) {
            centerId = window.parent.document.getElementById('parentSchoolList').options[selectIndex].value;
        }
        var childId = $("#childId").val();
        var projectType = $("#projectType").val();
        var scheduleTime = $("#scheduleTime").val();
        var teacherName = $("#teacherName").val();
        var isNewProgram = $("#isNewProgram").val();
        $.ajax({
            url: editPrefix+"/downloadTrainingProgramTeacher/"+childId+"/"+projectType+"/"+scheduleTime+"/"+teacherName+"/"+centerId+"/"+isNewProgram,
            type: "get",
            processData: false,
            contentType: false,
            success: function (result) {
                if (result.code == '0') {
                    window.open(result.msg)
                } else {
                    $.modal.alertWarning(result.msg);

                }
            }
        })
    }

    function downloadDataRecordTeacher() {
        var centerId = "";
        var selectIndex = window.parent.document.getElementById('parentSchoolList').selectedIndex;
        if (selectIndex >= 0) {
            centerId = window.parent.document.getElementById('parentSchoolList').options[selectIndex].value;
        }
        var childId = $("#childId").val();
        var projectType = $("#projectType").val();
        var scheduleTime = $("#scheduleTime").val();
        var teacherName = $("#teacherName").val();
        $.ajax({
            url: editPrefix+"/downloadDataRecordTeacher/"+childId+"/"+projectType+"/"+scheduleTime+"/"+teacherName+"/"+centerId,
            type: "get",
            processData: false,
            contentType: false,
            success: function (result) {
                if (result.code == '0') {
                    window.open(result.msg)
                } else {
                    $.modal.alertWarning(result.msg);

                }
            }
        })
    }

    function refresh(){
        $.table.search();
    }
</script>
</body>
</html>